package com.lanchetech.user.controller;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.request.UrlReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.AreaVO;
import com.lanchetech.entity.Job;
import com.lanchetech.entity.JobApply;
import com.lanchetech.entity.LogisticsCompany;
import com.lanchetech.entity.MsgUser;
import com.lanchetech.service.AreaService;
import com.lanchetech.service.FileService;
import com.lanchetech.service.LogisticsService;
import com.lanchetech.user.service.CommonService;
import com.lanchetech.user.service.JobApplyService;
import com.lanchetech.user.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value = "通用接口", tags = "例如文件上传等")
@RequestMapping("/api/common")
@RestController
public class CommonController {

    @Autowired
    FileService fileService;

    @Autowired
    AreaService areaService;

    @Autowired
    LogisticsService logisticsService;

    @Autowired
    JobService jobService;

    @Autowired
    JobApplyService jobApplyService;

    @Autowired
    CommonService commonService;

    @ApiOperation("上传文件，包括图片等")
    @PostMapping("/uploadFile")
    public ResultData<String> uploadFile(@RequestParam("file") MultipartFile file,
                                         @RequestParam(value = "oldImage", required = false, defaultValue = "") String oldImage) {
        return fileService.uploadFile(file, oldImage);
    }

    @ApiOperation("上传多文件多图片")
    @PostMapping("/uploadMultiFile")
    public ResultData<List<String>> uploadMultiFile(@RequestParam("files") MultipartFile[] files) {
        return fileService.uploadMultiFile(files);
    }


    @ApiOperation("获取省市区街道列表")
    @GetMapping("/getAreaList")
    public ResultData<List<AreaVO>> getAreaList(@RequestParam("level") Integer level, @RequestParam(value = "pid", required = false) Long pid) {
        return areaService.getAreaList(level, pid);
    }

    @ApiOperation("获取所有快递公司列表")
    @GetMapping("/getLogisticsCompanyList")
    public ResultData<List<LogisticsCompany>> getLogisticsCompanyList() {
        return logisticsService.getLogisticsCompanyList();
    }

    @ApiOperation("岗位分页列表")
    @PostMapping("/getJobPage")
    public ResultData<BasePageResp<Job>> getJobPage(@RequestBody PageReq req) {
        return jobService.getJobPage(req);
    }

    @ApiOperation("提交应聘岗位")
    @PostMapping("/editJobApply")
    public BaseResp editJobApply(@RequestBody JobApply jobApply) {
        return jobApplyService.editJobApply(jobApply);
    }

    @ApiOperation(value = "生成通用二维码")
    @PostMapping("/getCommonQrcode")
    public ResultData<String> getCommonQrcode(@RequestBody UrlReq url) {
        return fileService.getCommonQrcode(url);
    }

    @ApiOperation("获取平台客服")
    @GetMapping("/getPlatformMsgUser")
    public ResultData<MsgUser> getPlatformMsgUser(@RequestParam("msgUserId") Long msgUserId) {
        return commonService.getPlatformMsgUser(msgUserId);
    }

    @ApiOperation("获取普通用户的IM用户信息")
    @GetMapping("/getNormalMsgUser")
    public ResultData<MsgUser> getNormalMsgUser(@RequestParam("userId") Long userId) {
        return commonService.getNormalMsgUser(userId);
    }
}
